#include <sstream>
#include <time.h>
#include "u1.h"

using namespace std;

string timestamp() {
  time_t t;
  struct tm* ti;
  ostringstream oss;

  time(&t);
  ti = localtime(&t);
  oss.fill('0');
  oss.width(2); 
  oss << ti->tm_hour << ":";
  oss.width(2); 
  oss << ti->tm_min << ":";
  oss.width(2); 
  oss << ti->tm_sec;
  return oss.str();
}

std::ostream& operator<<(std::ostream& os, const StatCounter &sc)
{
  return os<<sc.count()<<" values in ["<<sc.min()<<", "<<sc.max()<<"], mean="
    <<sc.mean();
}

// Assume we have no similarity data for the given movie if the row is
// all exactly 0.
bool no_data_for(int movie_id, const symmetric_matrix<float> &S) {
  assert(movie_id > 0);
  size_t j = (size_t)(movie_id-1);
  for (size_t i = 0; i < S.size(); ++i) {
    if (i != j && S(j, i) != 0)
      return false;
  }
  return true;
}

/*
* Copyright (c) 2009 John Lees-Miller
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

